<template>
    <div>
            <van-tree-select v-model:main-active-index="activeIndex" height="96%" :items="items" >
              <template #content>
                <van-card v-for="(it,index) in goodsList" :key="it.id"
                :tag=it.label
                :desc="`${it.city_name}  ${it.district_name}`"
                :title=it.project_name
                 :thumb="`/api${it.banner}`" >
                 <template #tags>
             <van-tag plain type="danger">{{it.project_type}}</van-tag>
                 <van-tag plain type="danger">{{it.countdown}}</van-tag>
                  <van-tag plain type="danger">{{it.venue_name}}</van-tag>
               </template>
               <!-- 加入购物车 -->
                <template #footer>
                 <van-button size="mini" color="#01cb88" @click="bindUs(it)">查看详情</van-button>
                    <van-button size="mini" color="red" @click="addCart(index)">加入购物车</van-button>
                </template>
               </van-card>
               </template>
        </van-tree-select>
    </div>
</template>
    
    <script setup>
    import { ref, onMounted} from 'vue'
    import {RequestMangaAPI} from '../../api/goods'
    import {useRouter}from 'vue-router'
    import {useCounterStore} from '../../stores/users'
    import Ajax from '../../api/axios';
    import { Toast } from 'vant';
    const store = useCounterStore()
    const activeIndex = ref(0)
    const router =useRouter()
    const goodsList = ref([])
    const items = [{ text: '全部' }]
    let Cmoive =ref(0)
    // 漫展列表
    async function bindss() {
	const res = await RequestMangaAPI()
	if(res.code === 200){
        goodsList.value = res.data.rows
    }
}
function bindUs(it){
    Cmoive =it.id 
    router.push({path:'/ComicConDetails',query:{id:Cmoive}})
    
}   
   
    //加入购物车
    function addCart(_index) {
        console.log('>>>>>',goodsList.value[_index].id);
       Ajax({
        url:'/cart/add',
        method:'POST',
         data :{
            "userId": store.userInfo.id,
            "price": goodsList.value[_index].price_low,
            "id": goodsList.value[_index].id,
            "time": Date.now(),
            "count": 1,
            "name": goodsList.value[_index].project_name,
            "detailaddress": "待支付",
            "bgUrl": goodsList.value[_index].banner
        }
    }).then(d => {
        if (d.code === 200) {
            Toast.success('加入购物车成功')
        }
    })
}

onMounted(() => {
    bindss()
})
</script>
    
<style lang='scss' scoped></style>
    